<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>个人设置</title>

		<meta name="description" content="3 styles with inline editable feature" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="/assets/font-awesome/4.5.0/css/font-awesome.min.css" />

		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="/assets/css/jquery-ui.custom.min.css" />
		<link rel="stylesheet" href="/assets/css/jquery.gritter.min.css" />
		<link rel="stylesheet" href="/assets/css/select2.min.css" />
		<link rel="stylesheet" href="/assets/css/bootstrap-datepicker3.min.css" />
		<link rel="stylesheet" href="/assets/css/bootstrap-editable.min.css" />

		<!-- text fonts -->
		<link rel="stylesheet" href="/assets/css/fonts.googleapis.com.css" />

		<!-- ace styles -->
		<link rel="stylesheet" href="/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />

		<!--[if lte IE 9]>
			<link rel="stylesheet" href="/assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
		<![endif]-->
		<link rel="stylesheet" href="/assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="/assets/css/ace-rtl.min.css" />

		<!--[if lte IE 9]>
		  <link rel="stylesheet" href="/assets/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->
		<script src="/assets/js/ace-extra.min.js"></script>

		<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->

		<!--[if lte IE 8]>
		<script src="/assets/js/html5shiv.min.js"></script>
		<script src="/assets/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body class="no-skin">
		<div id="navbar" class="navbar navbar-default          ace-save-state">
			<div class="navbar-container ace-save-state" id="navbar-container">
				<button type="button" class="navbar-toggle menu-toggler pull-left" id="menu-toggler" data-target="#sidebar">
					<span class="sr-only">Toggle sidebar</span>

					<span class="icon-bar"></span>

					<span class="icon-bar"></span>

					<span class="icon-bar"></span>
				</button>

				<div class="navbar-header pull-left">
					<a href="/views/index.html" class="navbar-brand">
						<small>
							<i class="fa fa-leaf"></i>
							学生发展数据综合评价与分析系统
						</small>
					</a>
				</div>

				<div class="navbar-buttons navbar-header pull-right" role="navigation">
					<ul class="nav ace-nav">

						<li class="light-blue dropdown-modal">
							<a data-toggle="dropdown" href="#" class="dropdown-toggle">

								<img class="nav-user-photo us_photo" src="/assets/images/avatars/blank.jpg" alt="个人头像" style="background-color:#fff" />

								<span class="user-info">
							       <span id="us_name"></span>
								</span>

								<i class="ace-icon fa fa-caret-down"></i>
							</a>

							<ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
								<li>
									<a id="setting" target="_blank">
										<i class="ace-icon fa fa-cog"></i> 设置
									</a>
								</li>

								<li>
									<a id="profile" target="_blank">
										<i class="ace-icon fa fa-user"></i> 个人信息
									</a>
								</li>

								<li class="divider"></li>

								<li>
									<a href="/login.html" onclick="logout()">
										<i class="ace-icon fa fa-power-off"></i> 注销
									</a>
								</li>
							</ul>
						</li>
					</ul>
				</div>
			</div>
			<!-- /.navbar-container -->
		</div>

		<div class="main-container ace-save-state" id="main-container">
			<script type="text/javascript">
				try {
					ace.settings.loadState('main-container')
				} catch(e) {}
			</script>

			<div id="sidebar" class="sidebar                  responsive                    ace-save-state">
				<script type="text/javascript">
					try {
						ace.settings.loadState('sidebar')
					} catch(e) {}
				</script>

				<div class="sidebar-shortcuts" id="sidebar-shortcuts">
					<div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
						<button class="btn btn-success">
							<i class="ace-icon fa fa-signal"></i>
						</button>

						<button class="btn btn-info">
							<i class="ace-icon fa fa-pencil"></i>
						</button>

						<button class="btn btn-warning">
							<i class="ace-icon fa fa-users"></i>
						</button>

						<button class="btn btn-danger">
							<i class="ace-icon fa fa-cogs"></i>
						</button>
					</div>

					<div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
						<span class="btn btn-success"></span>

						<span class="btn btn-info"></span>

						<span class="btn btn-warning"></span>

						<span class="btn btn-danger"></span>
					</div>
				</div>
				<!-- /.sidebar-shortcuts -->

				<ul class="nav nav-list">
					<li class="">
						<a href="/views/index.html">
							<i class="menu-icon fa fa-tachometer"></i>
							<span class="menu-text"> 我的首页 </span>
						</a>

						<b class="arrow"></b>
					</li>
				</ul>
				<!-- /.nav-list -->

				<div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
					<i id="sidebar-toggle-icon" class="ace-icon fa fa-angle-double-left ace-save-state" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
				</div>
			</div>

			<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">我的首页</a>
							</li>

							<li class="active">设置</li>
						</ul>
						<!-- /.breadcrumb -->

					</div>

					<div class="page-content">

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<div class="hr dotted"></div>

								<div id="user-profile-3" class="user-profile row">
									<div class="col-sm-offset-1 col-sm-10">

										<div class="space"></div>

										<div class="form-horizontal">
											<div class="tabbable">
												<ul class="nav nav-tabs padding-16">
													<li class="active">
														<a data-toggle="tab" href="#edit-basic">
															<i class="green ace-icon fa fa-pencil-square-o bigger-125"></i> 基础信息
														</a>
													</li>

													<li>
														<a data-toggle="tab" href="#edit-password">
															<i class="blue ace-icon fa fa-key bigger-125"></i> 重置密码
														</a>
													</li>
												</ul>

												<div class="tab-content profile-edit-tab-content">
													<div id="edit-basic" class="tab-pane in active">
														<h4 class="header blue bolder smaller">个人头像</h4>

														<div class="form-group">

															<label class="col-sm-3 control-label no-padding-right" for="choose_photo" style="font-size: 15px;">选择头像</label>
															<div class="col-xs-12 col-sm-3">
																<span class="profile-picture">
																	<img class="us_photo" src="/assets/images/avatars/blank.jpg" style="display: block;" width="150px",height="150px"/>
																</span>
																<div class="space-6"></div>
																<input id="choose_photo" type="file" accept="image/jpeg, image/png, image/jpg" />
															</div>

														</div>

														<div class="space"></div>

														<h4 class="header blue bolder smaller">联系方式</h4>

														<div class="form-group">
															<label class="col-sm-3 control-label no-padding-right" for="us_phone">手机</label>

															<div class="col-sm-9">
																<span class="input-icon input-icon-left">
																	<i class="ace-icon fa fa-phone fa-flip-horizontal orange"></i>
																	<input class="input-medium input-mask-phone" type="text" id="us_phone" style="font-size: 15px;color: #000;"/>
																	</span>
															</div>
														</div>

														<div class="space-4"></div>

														<div class="form-group">
															<label class="col-sm-3 control-label no-padding-right" for="us_qq">QQ</label>

															<div class="col-sm-9">
																<span class="input-icon input-icon-left">
																	<i class="ace-icon fa fa-qq orange"></i>
																		<input type="text" id="us_qq" value="" style="font-size: 15px;color: #000;"/>
															</span>
															</div>
														</div>

														<div class="space-4"></div>

														<div class="form-group">
															<label class="col-sm-3 control-label no-padding-right" for="us_email">邮箱</label>

															<div class="col-sm-9">
																<span class="input-icon input-icon-left">
																		<i class="ace-icon fa fa-envelope orange"></i>
																		<input type="email" id="us_email" value="" style="font-size: 15px;color: #000;"/>
																</span>
															</div>
														</div>

														<div class="space"></div>
														<h4 class="header blue bolder smaller">我的简介</h4>

														<div class="form-group">
															<label class="col-sm-3 control-label no-padding-right" for="us_intro" style="font-size: 15px;">简介</label>

															<div class="col-sm-9">
																<textarea id="us_intro" style="width: 420px;height: 120px;font-size: 15px;color: #000;">这个人还没留下简介...</textarea>
															</div>
														</div>

														<div class="clearfix" style="margin-top: 25px;margin-left: 30px;">
															<div class="col-md-offset-3 col-md-9">
																<button class="btn btn-info" type="button" id="save1">
																	<i class="ace-icon fa fa-check bigger-110"></i>
																		保存
																</button>
															</div>
														</div>
													</div>

													<div id="edit-password" class="tab-pane">
														<div class="space-10"></div>

														<div class="form-group">
															<label class="col-sm-3 control-label no-padding-right" for="new_pw" style="font-size: 15px;">新密码</label>

															<div class="col-sm-9">
																<input type="password" id="new_pw" />
															</div>
														</div>

														<div class="space-4"></div>

														<div class="form-group">
															<label class="col-sm-3 control-label no-padding-right" for="again_pw" style="font-size: 15px;">确认密码</label>

															<div class="col-sm-9">
																<input type="password" id="again_pw" />
															</div>
														</div>
														<div class="clearfix" style="margin-top: 25px;margin-left: 30px;">
															<div class="col-md-offset-3 col-md-9">
																<button class="btn btn-info" type="button" id="save3">
																	<i class="ace-icon fa fa-check bigger-110"></i>
																		保存
																</button>
															</div>
														</div>
													</div>

												</div>
											</div>

										</div>

									</div>
									<!-- /.span -->
								</div>
								<!-- /.user-profile -->

								<!-- PAGE CONTENT ENDS -->
							</div>
							<!-- /.col -->
						</div>
						<!-- /.row -->
					</div>
					<!-- /.page-content -->
				</div>
			</div>
			<!-- /.main-content -->

			<div class="footer">
				<div class="footer-inner">
					<div class="footer-content">
						<span class="bigger-120">
							<span class="blue bolder" style="margin-right: 10px;">学生发展数据综合评价与分析系统</span> 苏州科技大学 &copy; 2018-2019
						</span>
					</div>
				</div>
			</div>

			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
			</a>
		</div>
		<!-- /.main-container -->

		<!-- basic scripts -->

		<!--[if !IE]> -->
		<script src="/assets/js/jquery-2.1.4.min.js"></script>
		<script src="/assets/js/jquery.cookie.js"></script>
		<script src="/assets/js/sddb.util.js"></script>

		<!-- <![endif]-->

		<!--[if IE]>
<script src="/assets/js/jquery-1.11.3.min.js"></script>
<![endif]-->
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='/assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
		</script>
		<script src="/assets/js/bootstrap.min.js"></script>

		<!-- page specific plugin scripts -->

		<!--[if lte IE 8]>
		  <script src="/assets/js/excanvas.min.js"></script>
		<![endif]-->
		<script src="/assets/js/jquery-ui.custom.min.js"></script>
		<script src="/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="/assets/js/jquery.gritter.min.js"></script>
		<script src="/assets/js/bootbox.js"></script>
		<script src="/assets/js/jquery.easypiechart.min.js"></script>
		<script src="/assets/js/bootstrap-datepicker.min.js"></script>
		<script src="/assets/js/jquery.hotkeys.index.min.js"></script>
		<script src="/assets/js/bootstrap-wysiwyg.min.js"></script>
		<script src="/assets/js/select2.min.js"></script>
		<script src="/assets/js/spinbox.min.js"></script>
		<script src="/assets/js/bootstrap-editable.min.js"></script>
		<script src="/assets/js/ace-editable.min.js"></script>
		<script src="/assets/js/jquery.maskedinput.min.js"></script>

		<!-- ace scripts -->
		<script src="/assets/js/ace-elements.min.js"></script>
		<script src="/assets/js/ace.min.js"></script>

		<!-- inline scripts related to this page -->

		<script>
			jQuery(function($) {

				//用户点击输入邮箱时，自动填入qq邮箱
				$("#us_email").click(function() {
					$("#us_email").val($("#us_qq").val() + "@qq.com");
				});

				//选择照片的更改事件
				$("#choose_photo").change(function() {
					//获取input file的files文件数组;
					//$('#choose')获取的是jQuery对象，.get(0)转为原生对象;
					//这边默认只能选一个，但是存放形式仍然是数组，所以取第一个元素使用[0];
					var file = $('#choose_photo').get(0).files[0];
					//创建用来读取此文件的对象
					var reader = new FileReader();
					//使用该对象读取file文件
					reader.readAsDataURL(file);
					//读取文件成功后执行的方法函数
					reader.onload = function(e) {
						//选择所要显示图片的img，要赋值给img的src
						//base64编码格式的地址
						$('.us_photo').get(1).src = e.target.result;
					}
				});

				//获取用户基本信息

				$.ajax({
					type: "post",
					url: "/user/getUserInfo",
					dataType: "json",
					data: {
						"us_id": $.cookie("us_id")
					},
					success: function(data) {

						$("#us_phone").val(data.us_phone);
						$("#us_qq").val(data.us_qq);
						$("#us_email").val(data.us_email);
						$("#us_intro").val(data.us_intro);

					},
					error: function(err) {
						alert("获取用户信息失败!")
					}
				});

				$("#save1").click(function() {

					//如果更改了头像，则需要上传头像
					if($("#choose_photo").val() !== "") {
						//上传头像
						var formData = new FormData();
						var file = $("#choose_photo")[0].files[0];
						formData.append("us_photo", file);
						formData.append("us_id", $.cookie("us_id"));

						$.ajax({
							type: "post",
							url: "/user/uploadPhoto",
							data: formData,
							processData: false,
							contentType: false,
							dataType: "json",
							success: function(data) {
								alert(data.info);
								if(data.success == true) {
									//刷新界面
									location.reload();
								}
							},
							error: function(err) {
								alert("上传头像失败!");
							}

						});
					}

					//更新用户基本信息
					$.ajax({
						type: "post",
						url: "/user/editUserInfo",
						dataType: "json",
						data: {
							"us_id": $.cookie("us_id"),
							"us_phone": $("#us_phone").val(),
							"us_qq": $("#us_qq").val(),
							"us_email": $("#us_email").val(),
							"us_intro": $("#us_intro").val()
						},
						success: function(data) {
							alert(data.info);
							if(data.success == true) {
								//刷新界面
								location.reload();
							}
						},
						error: function(err) {
							alert("用户信息更新失败!");
						}
					});
				});

			});
		</script>

		<!--重置密码-->
		<script>
			jQuery(function($) {
				$("#save3").click(function() {
					if($("#new_pw").val() != $("#again_pw").val()) {
						alert("两次输入的密码不一致!");
						$("#new_pw").val("");
						$("#again_pw").val("");
						return;
					}
					$.ajax({
						type: "post",
						url: "/user/resetPassword",
						dataType: "json",
						data: {
							"us_id": $.cookie("us_id"),
							"us_password": $("#again_pw").val()
						},
						success: function(data) {
							alert(data.info + ",需要重新登录");
							//注销本账户
							logout();
							//关闭父窗口
							window.opener.close();
							//带回到登陆界面
							window.open("/login.html", "_self");

						},
						error: function(err) {
							alert("重置失败!");
						}
					});
				});
			});
		</script>

		<script type="text/javascript">
			jQuery(function($) {

				//editables on first profile page
				$.fn.editable.defaults.mode = 'inline';
				$.fn.editableform.loading = "<div class='editableform-loading'><i class='ace-icon fa fa-spinner fa-spin fa-2x light-blue'></i></div>";
				$.fn.editableform.buttons = '<button type="submit" class="btn btn-info editable-submit"><i class="ace-icon fa fa-check"></i></button>' +
					'<button type="button" class="btn editable-cancel"><i class="ace-icon fa fa-times"></i></button>';

				//editables 

				//text editable
				$('#username')
					.editable({
						type: 'text',
						name: 'username'
					});

				//select2 editable
				var countries = [];
				$.each({
					"CA": "Canada",
					"IN": "India",
					"NL": "Netherlands",
					"TR": "Turkey",
					"US": "United States"
				}, function(k, v) {
					countries.push({
						id: k,
						text: v
					});
				});

				var cities = [];
				cities["CA"] = [];
				$.each(["Toronto", "Ottawa", "Calgary", "Vancouver"], function(k, v) {
					cities["CA"].push({
						id: v,
						text: v
					});
				});
				cities["IN"] = [];
				$.each(["Delhi", "Mumbai", "Bangalore"], function(k, v) {
					cities["IN"].push({
						id: v,
						text: v
					});
				});
				cities["NL"] = [];
				$.each(["Amsterdam", "Rotterdam", "The Hague"], function(k, v) {
					cities["NL"].push({
						id: v,
						text: v
					});
				});
				cities["TR"] = [];
				$.each(["Ankara", "Istanbul", "Izmir"], function(k, v) {
					cities["TR"].push({
						id: v,
						text: v
					});
				});
				cities["US"] = [];
				$.each(["New York", "Miami", "Los Angeles", "Chicago", "Wysconsin"], function(k, v) {
					cities["US"].push({
						id: v,
						text: v
					});
				});

				var currentValue = "NL";
				$('#country').editable({
					type: 'select2',
					value: 'NL',
					//onblur:'ignore',
					source: countries,
					select2: {
						'width': 140
					},
					success: function(response, newValue) {
						if(currentValue == newValue) return;
						currentValue = newValue;

						var new_source = (!newValue || newValue == "") ? [] : cities[newValue];

						//the destroy method is causing errors in x-editable v1.4.6+
						//it worked fine in v1.4.5
						/**			
						$('#city').editable('destroy').editable({
							type: 'select2',
							source: new_source
						}).editable('setValue', null);
						*/

						//so we remove it altogether and create a new element
						var city = $('#city').removeAttr('id').get(0);
						$(city).clone().attr('id', 'city').text('Select City').editable({
							type: 'select2',
							value: null,
							//onblur:'ignore',
							source: new_source,
							select2: {
								'width': 140
							}
						}).insertAfter(city); //insert it after previous instance
						$(city).remove(); //remove previous instance

					}
				});

				$('#city').editable({
					type: 'select2',
					value: 'Amsterdam',
					//onblur:'ignore',
					source: cities[currentValue],
					select2: {
						'width': 140
					}
				});

				//custom date editable
				$('#signup').editable({
					type: 'adate',
					date: {
						//datepicker plugin options
						format: 'yyyy/mm/dd',
						viewformat: 'yyyy/mm/dd',
						weekStart: 1

						//,nativeUI: true//if true and browser support input[type=date], native browser control will be used
						//,format: 'yyyy-mm-dd',
						//viewformat: 'yyyy-mm-dd'
					}
				})

				$('#age').editable({
					type: 'spinner',
					name: 'age',
					spinner: {
						min: 16,
						max: 99,
						step: 1,
						on_sides: true
						//,nativeUI: true//if true and browser support input[type=number], native browser control will be used
					}
				});

				$('#login').editable({
					type: 'slider',
					name: 'login',

					slider: {
						min: 1,
						max: 50,
						width: 100
						//,nativeUI: true//if true and browser support input[type=range], native browser control will be used
					},
					success: function(response, newValue) {
						if(parseInt(newValue) == 1)
							$(this).html(newValue + " hour ago");
						else $(this).html(newValue + " hours ago");
					}
				});

				$('#about').editable({
					mode: 'inline',
					type: 'wysiwyg',
					name: 'about',

					wysiwyg: {
						//css : {'max-width':'300px'}
					},
					success: function(response, newValue) {}
				});

				$('#profile-feed-1').ace_scroll({
					height: '250px',
					mouseWheelLock: true,
					alwaysVisible: true
				});

				$('a[ data-original-title]').tooltip();

				$('.easy-pie-chart.percentage').each(function() {
					var barColor = $(this).data('color') || '#555';
					var trackColor = '#E2E2E2';
					var size = parseInt($(this).data('size')) || 72;
					$(this).easyPieChart({
						barColor: barColor,
						trackColor: trackColor,
						scaleColor: false,
						lineCap: 'butt',
						lineWidth: parseInt(size / 10),
						animate: false,
						size: size
					}).css('color', barColor);
				});

				///////////////////////////////////////////

				//right & left position
				//show the user info on right or left depending on its position
				$('#user-profile-2 .memberdiv').on('mouseenter touchstart', function() {
					var $this = $(this);
					var $parent = $this.closest('.tab-pane');

					var off1 = $parent.offset();
					var w1 = $parent.width();

					var off2 = $this.offset();
					var w2 = $this.width();

					var place = 'left';
					if(parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) place = 'right';

					$this.find('.popover').removeClass('right left').addClass(place);
				}).on('click', function(e) {
					e.preventDefault();
				});

				$('.input-mask-phone').mask('999 9999 9999');

				$('#user-profile-3').find('input[type=file]').ace_file_input('show_file_list', [{
					type: 'image'
				}]);

				////////////////////
				//change profile
				$('[data-toggle="buttons"] .btn').on('click', function(e) {
					var target = $(this).find('input[type=radio]');
					var which = parseInt(target.val());
					$('.user-profile').parent().addClass('hide');
					$('#user-profile-' + which).parent().removeClass('hide');
				});

				/////////////////////////////////////
				$(document).one('ajaxloadstart.page', function(e) {
					//in ajax mode, remove remaining elements before leaving page
					try {
						$('.editable').editable('destroy');
					} catch(e) {}
					$('[class*=select2]').remove();
				});
			});
		</script>
	</body>

</html>